package com.lagou.edu.controller;

import com.lagou.edu.service.CreateCodeService;
import com.lagou.edu.service.EmailService;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/code")
public class CodeController {

    @Autowired
    private CreateCodeService createCodeService;

    @Reference
    private EmailService emailService;

//    @Reference
//    private UserService userService;

    @RequestMapping("/create/{email}")
    public boolean  createCode(@PathVariable String email){
//        boolean registered = userService.isRegistered(email);
//        if (registered) {
//            return false;
//        }

        String code = createCodeService.createCode(email);

        // 调用email发送邮件
        emailService.sendCode(email, code);

        return true;
    }


}
